home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- *
- * Apple Macintosh Developer Technical Support
- *
- * Installer 3.2 sample: Action Atoms
- *
- * File: SetFolderIcon.c - c Source
- *
- * by: Rich Kubota
- *
- * Copyright © 1990-1992 Apple Computer, Inc.
- * All rights reserved.
- *
- * Purpose: Sample to demonstrate setting a custom folder icon. The script
- * needs to copy the folder icon file as demonstrated in the
- * CustomFoldIconInstall.r script. This code resource must then be called
- * to clear the folder's init'd bit and to set the folders "Use Custom Icon" bit.
- * In the selector field of the 'inaa' resource, pass in the id of the target
- * 'infs' resource id for the icon. The code resource gets the resource, converts the
- * partial path name field to a pascal string for the enclosing folder. The
- * code resource calls PHGetCatInfo to get the directory info. The necessary
- * bits are set/cleared, and PBSetCatInfo is called. The return value of
- * noErr is always returned so as not to abort the installation.
- *----------------------------------------------------------------------------*/
-
- #if 0
-
- C -r -b SetFolderIcon.c
- Link -ra =resPurgeable -t rsrc -c RSED -rt infn=10000 ∂
- -m SETFOLDERICON -sg SetFolderIcon ∂
- SetFolderIcon.c.o ∂
- "{Libraries}"Interface.o ∂
- -o SetFolderIcon.rsrc
-
- #endif
-
- #include <Types.h>
- #include <Resources.h>
- #include <Files.h>
- #include "ActionAtomIntf.h"
-
- /* define record structure of 'infs' resource so that we can access the target file path */
-
- struct infsRec {
- long fileType;
- long creator;
- long creationDate;
- short fileSpecFlags;
- Str255 pathName;
-
- };
-
- typedef struct infsRec infsRec;
- typedef infsRec **infsHdl;
-
- /* protoypes */
- OSErr StripFileName(char *str);
-
- pascal long SETFOLDERICON(AAPBRecPtr myAAPBPtr)
- {
- OSErr err;
- infsHdl resH;
- CInfoPBRec info;
- DInfo *myDirInfo;
-
- if (myAAPBPtr->whichStage == after) /* only run if doing post-installation */
- /* Note 1. action atoms marked as actAfter will also
- * *receive a cleanUpCancel message if the
- * installation is cancelled so we need to test
- * the stage here, else we could get called
- * twice.
- * Note 2. to be more robust, we might also include
- * the option to respond to a cleanUpCancel message to
- * remove the icon and folder
- */
- {
- resH = (infsHdl)GetResource('infs', myAAPBPtr->aaRefCon);
- if (resH) {
- if (StripFileName((*resH)->pathName) == noErr) {
- info.dirInfo.ioCompletion = nil;
- info.dirInfo.ioVRefNum = myAAPBPtr->targetVRefNum;
- info.dirInfo.ioNamePtr = (*resH)->pathName;
- info.dirInfo.ioFDirIndex = 0;
- info.dirInfo.ioDrDirID = 0;
-
- if (PBGetCatInfo(&info, false) == noErr) {
- myDirInfo = &info.dirInfo.ioDrUsrWds;
- myDirInfo->frFlags &= 0xFEFF;
- // clear the init'd bit
- myDirInfo->frFlags |= 0x0400;
- // set the "Use Custom Folder Icon" bit
-
- // now that the ioDrDirID field is filled in corectly
- // let's use it to identify the directory instead of the name ptr.
- info.dirInfo.ioNamePtr = nil;
- info.dirInfo.ioFDirIndex = -1;
- err = PBSetCatInfo(&info,false);
- }
- }
- ReleaseResource((Handle)resH);
- }
- }
- return noErr; // Since the installation reached this point, dont abort
- }
-
- // This routine strips the filename and the preceding ':' character from the
- // pathname.
- // Input - pointer to file pathname
- // Output - modifies pointer
- OSErr StripFileName(char *str)
- {
- unsigned char len = str[0];
-
- while ((str[len] != ':') && (len > 0))
- len--;
-
- if (len > 0) {
- str[0] = len - 1; // parse the ":" from the end of the pathname
- return noErr;
- }
- return -1;
- }